import { Util } from "./Util";

export enum ETalent {
    POWER = 0,
    DEFENSE = 1,
}


export type TalentDataValues = {
    name: string,
    desc: string,
}


export const TalentData = {
    [ETalent.POWER]: { name: '力量', desc: '增加攻击力' },
    [ETalent.DEFENSE]: { name: '防御', desc: '增加防御力' },
}

export class Talent {
    id: ETalent;
    level: number;
    constructor(id: ETalent, level: number = 0) {
        this.id = id;
        this.level = level;
    }

    getData() {
        return TalentData[this.id];
    }
}

export class TalentManager {
    
    talentList: Record<number, Talent> = {};

    constructor() {
        this.talentList[ETalent.POWER]= new Talent(ETalent.POWER);
        this.talentList[ETalent.DEFENSE]= new Talent(ETalent.DEFENSE)
    }
    
    getPackage() {
        let data = [];
        data[ETalent.POWER] = this.talentList[ETalent.POWER].level;
        data[ETalent.DEFENSE] = this.talentList[ETalent.DEFENSE].level;
        return data;
    }

    setPackage(data: {}) {
        this.talentList[ETalent.POWER].level = Util.getSafeData<number>(data[ETalent.POWER], 0);
        this.talentList[ETalent.DEFENSE].level = Util.getSafeData<number>(data[ETalent.DEFENSE], 0);
    }
}